<template>
  <div>
    <div class="page-title">服务协议</div>
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="内容">
        <el-input type="textarea" v-model="form.content"></el-input>
        <div id="toolbar"></div>
        <div>
          <div id="editor_id" style="height: 300px;background: #38bcd9;" v-html="html"></div>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="success" icon="el-icon-check" @click="submit">添加</el-button>
        <el-button icon="el-icon-close" @click="cancel">取消</el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import {
  request_agreement_find,
  request_agreement_update,
} from '@/util/api'
import E from 'wangeditor'
export default {
  name: 'AddManager',
  data() {
    return {
      editor:null,
      editorContent:'',
      form: {
        id:0,
        content: '',
      },
    }
  },
  props:{
    content:{
      type:String,
      require:false
    }
  },
  mounted() {
    this.init();
    console.log(this.form.content);
    var editor = new E('#toolbar','#editor_id')
    editor.config.onchange=(html)=>{
      this.form.content = html
    }
    editor.create()
    console.log(this.form.content,'后执行');
    /*this.$nextTick(() => {
      // 绑定值
      editor.txt.html(this.form.content);
    })*/
    editor.txt.html('1564654654')
  },
  methods: {
    init() {
      this.$nextTick(() => {
        request_agreement_find()
            .then((res) => {
              const result = res.data;
              if (result.code == 200) {
                this.form.content = result.data.content;
                console.log(this.form.content,'先执行')
                this.form.id = result.data.id;
              }
            })
            .catch();
      });
    },
    getContent: function() {
      alert(this.editorContent);
    },
    // 提交
    submit() {
      if (this.form.content == '') {
        this.$notify.info({
          title: '系统提示',
          message: '请输入内容',
          offset: 70
        })
        return false
      }

      request_agreement_update(this.form).then(res => {
        const result = res.data
        if (result.code == 200) {
          this.$notify.success({
            title: '系统提示',
            message: '修改成功',
            offset: 70
          })
          this.$router.push('/user_agreement')
        }
      }).catch()
    },
    // 取消
    cancel() {
      this.$router.push('/user_agreement')
    }
  }
}
</script>

<style>
</style>